#!/usr/bin/env bash
set -e

VERSION=2.7.0

rm -rf upstream

mkdir upstream
cd upstream
wget -c https://codeload.github.com/HewlettPackard/netperf/zip/netperf-$VERSION -O netperf-$VERSION.zip
unzip netperf-$VERSION.zip
mv netperf-netperf-$VERSION netperf-$VERSION
cd netperf-$VERSION

./configure

make CFLAGS="-fcommon"
mkdir bin
cp src/netperf bin/
cp src/netserver bin/

make clean
make CFLAGS="-fPIC -shared -fcommon"
mkdir osv
cp src/netserver osv/netserver.so
cp src/netserver ../../netserver.so
cp src/netperf osv/netperf.so
cp src/netperf ../../netperf.so
cd ../..

cat > usr.manifest <<EOF
# This file is automatically generated
/tools/netserver.so: \${MODULE_DIR}/upstream/netperf-$VERSION/osv/netserver.so
/tools/netperf.so: \${MODULE_DIR}/upstream/netperf-$VERSION/osv/netperf.so
EOF
